<template>
  <div class="todo-remind">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>我的待办</span>
        <!-- <el-button
          style="float: right; padding: 3px 0"
          type="text"
          @click="tosettings()"
          >待办设置</el-button
        > -->
      </div>
      <h3>询价系统</h3>
      <div class="todo-remindbox">
        <el-form ref="form" label-width="167px">
          <div>
            <div slot="header" class="clearfix">
              <span>客户询价需求</span>
            </div>
            <el-row class="box">
              <el-col
                :span="8"
                v-for="(item, index) in remindList.inquiryDemand"
                :key="index"
              >
                <el-form-item
                  v-if="!!item.isShow"
                  :label="lablefn(item.menuId)"
                >
                  <div
                    class="account"
                    @click="dbClickfn(item.status.toString(), item.menuId)"
                  >
                    ({{ item.count }})
                  </div>
                </el-form-item>
              </el-col>
            </el-row>
            <div slot="header" class="clearfix">
              <span>客户订货需求</span>
            </div>
            <el-row class="box">
              <el-col
                :span="8"
                v-for="(item, index) in remindList.orderDemand"
                :key="index"
              >
                <el-form-item
                  v-if="!!item.isShow"
                  :label="lablefn(item.menuId)"
                >
                  <div
                    class="account"
                    @click="dbClickfn(item.status.toString())"
                  >
                    ({{ item.count }})
                  </div>
                </el-form-item>
              </el-col>
            </el-row>
            <div slot="header" class="clearfix">
              <span>采购询价</span>
            </div>
            <el-row class="box">
              <el-col
                :span="8"
                v-for="(item, index) in remindList.purchaseInquiry"
                :key="index"
              >
                <el-form-item
                  v-if="!!item.isShow"
                  :label="lablefn(item.menuId)"
                >
                  <div
                    class="account"
                    @click="dbClickfn(item.status.toString(), item.menuId)"
                  >
                    ({{ item.count }})
                  </div>
                </el-form-item>
              </el-col>
            </el-row>
          </div>
        </el-form>
      </div>
    </el-card>
  </div>
</template>
<script>
import { mapState, mapActions } from 'vuex';
import * as Utils from './utils';
import Cookies from 'js-cookie';

export default {
  data () {
    return {};
  },
  computed: {
    ...mapState('sourcing', {
      remindList: (state) => state.demandInquery.remindList
    })
  },
  mounted () {
    // this.setTimer();
    /* setInterval(() => {
      this.initeventRemindList();
    }, 300000); */
  },
  methods: {
    ...mapActions('sourcing/demandInquery', [
      'eventRemindList' // 获取待办事项
    ]),
    setTimer () {
      const ucToken = Cookies.get().uc_token;
      let timer;
      if (!ucToken) {
        timer = setTimeout(() => {
          this.setTimer();
        }, 1000);
      } else {
        this.initeventRemindList();
        clearTimeout(timer);
      }
    },
    lablefn (menuid) {
      return Utils.REMIND_LABLE(menuid);
    },
    initeventRemindList () {
      const data = {};
      this.eventRemindList({
        payload: {
          data
        }
      });
    },
    dbClickfn (status, menuId) {
      let topageurl = '';
      if (
        (status == '10' && menuId == 1) ||
        (status == '20' && menuId == 2) ||
        status == '15'
      ) {
        topageurl = 'demandInquiry';
      } else {
        if (status == '10' || status == '20' || status == '60') {
          topageurl = 'demandOrder';
        }
      }

      if (status == '100' && menuId == 7) {
        topageurl = 'inquiry';
      } else {
        if (status == '100' || status == '200' || status == '300') {
          topageurl = 'order';
        }
      }
      this.$router.push({ name: topageurl, query: { sts: status } });
    },
    tosettings () {
      // this.$router.push({ name: 'todoSetting' });
    }
  }
};
</script>
<style lang="less" scoped>
.todo-remind {
  .todo-remindbox {
    margin-top: 10px;
    .box .account {
      color: coral;
      cursor: pointer;
    }
    .text {
      font-size: 14px;
    }

    .item {
      margin-bottom: 18px;
    }

    .clearfix:before,
    .clearfix:after {
      display: table;
      content: "";
    }
    .clearfix:after {
      clear: both;
    }
  }
}
</style>
